import pymysql.cursors
from pymysql import Connection

conn = Connection(
    host="localhost",
    port=3306,
    user="root",
    password=""
)

# print(conn.get_server_info())

# cursor = conn.cursor()  # 获取游标对象

cursor = conn.cursor(pymysql.cursors.DictCursor)  # 返回字典格式

conn.select_db("python")  # 选择数据源

cursor.execute("select * from user")

result = cursor.fetchall()

# 关闭连接
conn.close()

for field in result:
    print(field)
"""
查询操作
cursor.execute("select * from user")

result = cursor.fetchall()

for v in result:
    print(v)
"""

"""
DML操作

conn.autocommit(True) # 自动提交
res = cursor.execute("insert into user(name) values ('孙七')")
print(res)
# conn.commit()  手动提交
"""
